#include "StdAfx.h"
#include "TimerManager.h"
#include "P2P.h"

CP2PTimerManager::CP2PTimerManager( CP2P* p2p )
{
    m_p2p = p2p;
}

CP2PTimerManager::~CP2PTimerManager(void)
{
}

void CP2PTimerManager::OnTimer( HTIMER hTimer, void* pData )
{
    CTimer* timer = (CTimer*)pData;

    if (timer->get_timer() != hTimer)
    {
        return;
    }

    timer->OnTimer();
}

bool CP2PTimerManager::AddTimer( CTimer* timer, bool exact /*= false*/ )
{
    HTIMER timer_handle = m_p2p->get_timer_manager()->AddTimer(timer->get_elapse(), timer->get_count(), timer, exact);
    if (!timer_handle)
    {
        return false;
    }

    timer->set_timer(timer_handle);

    return true;
}

bool CP2PTimerManager::ModTimer( CTimer* timer, bool exact /*= false*/ )
{
    return m_p2p->get_timer_manager()->ModTimer(timer->get_timer(), timer->get_elapse(), timer->get_count(), timer, exact);
}

void CP2PTimerManager::DelTimer( CTimer* timer )
{
    m_p2p->get_timer_manager()->DelTimer(timer->get_timer());
    timer->set_timer(NULL);
}

void CHostCheck::OnTimer( void )
{

}
